<template>
  <div class="main-container">
    <div class="main-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>系统配置管理</el-breadcrumb-item>
        <el-breadcrumb-item>修改密码</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="wrap">
      <div class="content">
        <el-form class="mt-30" ref="form" :model="form" label-width="100px" style="width: 400px;">
          <el-form-item label="原密码" prop="password" :rules="[ { required: true, message: '原密码不能为空'}]">
            <el-input v-model="form.password" type="password"></el-input>
          </el-form-item>
          <el-form-item label="新密码" prop="newPassword" :rules="[ { required: true, message: '新密码不能为空'}]">
            <el-input v-model="form.newPassword" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">修改密码</el-button>
            <el-button @click="onReset">清空</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        form: {
          username: '',
          password: '',
          newPassword: '',
        }
      }
    },
    activated() {
      this.onReset()
    },
    methods: {
      // 提交
      onSubmit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.$api.modifyPassword(this.form).then(res => {
              if(res.success) {
                this.$message.success('修改成功，请重新登录')
                this.$utils.logout()
              }
            })
          }
        })
      },
      // 清空
      onReset() {
        this.$refs.form.resetFields()
      }
    }
  }
</script>

<style>

 
</style>
